<script>
  //返回最快的请求，不能是成功还是失败状态的都可以，最快进行
  function fn(time, flag, data) {
    return function (resolve, reject) {
      setTimeout(() => {
        if (flag) {
          resolve(data)
        } else {
          reject(data)
        }
      }, time)
    }
  }
  const p1 = new Promise(fn(100, true, 1))

  // p1.then((res) => {
  //   console.log(res)
  // })

  const p2 = new Promise(fn(200, true, 2))

  // p2.catch((err) => {
  //   console.log("error:", err)
  // })

  const p3 = new Promise(fn(100, true, 3))

  let allSettledOut = Promise.allSettled([p1, p2, p3])
  allSettledOut.then(
    (res) => console.log("success", res),
    (err) => console.log("failure", err)
  )

  let anyOut = Promise.any([p1, p2, p3])
  anyOut.then(
    (res) => console.log("success", res),
    (err) => console.log("failure", err)
  )
  // p3.catch((err) => {
  //   console.log("error:", err)
  // })
</script>
